package org.example.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/10/19
 * Email haijunzhou@hnit.edu.cn
 */
public class MyBatisXmlParser {

    public void parse() throws IOException {
        Document doc = Jsoup.parse(
                new File("E:\\上课视频\\143\\yc143\\maven\\src\\main\\resources\\mybatis.xml"),
                "utf-8");
        // 返回一组元素
        Elements environments = doc.getElementsByTag("environments ");
        if (environments.isEmpty()) {
            return;
        }
        // 返回一个元素
        Element element = environments.get(0);

        String aDefault = element.attr("default");

        Element environment = doc.getElementById(aDefault);
        Elements propertys = environment.getElementsByTag("property");

        for (Element property : propertys) {
            String name = property.attr("name");
            String value = property.attr("value");
            System.out.println( name + " = " + value);
        }

    }


}
